package com.stone.drawable;
//子包想访问父包中的资源，必须导入父包中的R
//而不能是android.R
import com.stone.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;
//该类说明的是如何动态的进行画画
public class MyDrawable extends Activity{
   @Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
    //动态的设置应该有一个布局才可以
	setContentView(R.layout.drawabel1);
	FrameLayout layout=(FrameLayout)findViewById(R.id.FrameLayout01);
	layout.addView(new Ball(this,50,50,25));
	//android.view.View中的onTouchListener监听。
	layout.setOnTouchListener(new OnTouchListener() {
		
		public boolean onTouch(View v, MotionEvent event) {
			float x=event.getX();
			float y=event.getY();
			FrameLayout fv=(FrameLayout)v;
			//此处需要注意的地方getParent
			fv.addView(new Ball(getParent(),x,y,10));
			
			return true;
		}
	});
}
   private class Ball extends View{
    private final float x;
    private final float y;
    private final float r;
    private final Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
	public Ball(Context context,float x,float y,int r) {
		super(context);
		paint.setColor(Color.RED);
		this.x=x;
		this.y=y;
		this.r=r;
	}
	 @Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		
		canvas.drawCircle(x, y, r, paint);
	}   
   }       
    
}
